/*
 * 文件名：LandProfitController.java
 * 版权：Copyright by www.infopub.top
 * 描述：
 * 修改人：huangxiaolang
 * 修改时间：2020年1月12日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package top.infopub.mgr.fia.web;


import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.fia.service.BankInfoService;
import top.infopub.mgr.fia.vo.BankInfoVo;
import top.infopub.model.fia.BankInfo;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;

import java.text.ParseException;


@Controller
@RequestMapping("/bankInfo")
public class BankInfoController {
    @Autowired
    private BankInfoService bankInfoService;

    /**
     * 列表
     * @return
     */
    @RequestMapping("/list")
    public String list() {
        return "fia/lay-bankInfo-list";
    }
    
    
    /**
     * 银行台账列表数据查询
     * @return
     * @throws ParseException 
     */
    @RequestMapping("/queryDataByCondition")
    @ResponseBody
    public RspVo<BankInfo> queryDataByCondition(BankInfoVo bankInfoVo, ParamPage paramPage) throws ParseException {
        PageInfo<BankInfo> page = bankInfoService.queryBankInfoPage(bankInfoVo, paramPage);
        return RspVo.getSuccessResponse(page.getTotal(), page.getList());
    }

    /**
     * 银行台账新增/编辑
     * @throws ParseException 
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/saveOrEdit")
    @ResponseBody
    public RspVo saveOrEdit(BankInfo bankInfo) {
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        return bankInfoService.saveOrEdit(bankInfo, vo);
    }
    
    /**
     * 启用/禁用
     * @throws ParseException 
     */
    @RequestMapping("/enOrDisable")
    @ResponseBody
    public RspVo cancel(String id, String accountStatus) {
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        return bankInfoService.modifyAccountStatus(id, accountStatus,  vo);
    }
    
    /**
     * 根据id查询详情
     */
    @RequestMapping("/queryById")
    @ResponseBody
    public RspVo queryById(String id) {
        if (StringUtils.isBlank(id)) return RspVo.getFailureResponse(400, "参数id不能为空~");
        BankInfo bankInfo = bankInfoService.selectByPrimaryKey(id);
        if (bankInfo == null) return RspVo.getFailureResponse(400, "数据不存在~");
        return RspVo.getSuccessResponse(bankInfo);
    }
}
